﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;

namespace Water.Web.JSON
{
    public class JSONSettingUtil
    {
        public static void SetHashtable(Hashtable ht,object key, object value, bool isString)
        {
 
            if (ht.ContainsKey(key))
                    ht.Remove(key);
            if(!string.IsNullOrEmpty(value.ToString()))
            {
                if (isString)
                    ht.Add(key, "\'" + value + "\'");
                else if (value is bool)
                    ht.Add(key, value.ToString().ToLower());
                else
                    ht.Add(key, value + "");
            }

        }
        public static void SetHashtable(Hashtable ht,object key, object value)
        {
            SetHashtable(ht,key, value, false);
        }
        public static string ToKeyValue(Hashtable ht)
        {
            string strReturn = "";
            foreach (DictionaryEntry item in ht)
            {
                strReturn += item.Key + ":" + item.Value.ToString()+ ",";

            }
            if (strReturn.EndsWith(","))
                strReturn = strReturn.Substring(0, strReturn.Length - 1);
            return strReturn ;
        }
    }
}
